package com.sanbi.demo.bootadmin.client.logback.controller;

import com.sanbi.common.util.NumberUtil;
import com.sanbi.demo.bootadmin.client.logback.bean.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author 江南一点雨
 * @Site www.javaboy.org 2019-06-05 9:38
 */
@Slf4j
@RestController
@RequestMapping("test")
public class TestController {
    @GetMapping("addUser")
    public User addUser() {
        User user = new User();
        int id= NumberUtil.getRandomNum(10000);
        user.setId(id);
        user.setUsername("zhang san "+id);
        user.setAddress("test address "+id);
        user.setAge(18+id);
        user.setEmail("test@163.com");
        user.setGender(1);
        user.setBirthday(LocalDateTime.now());

        log.info("info --- create a new user: {}",user);
        log.error("error --- create a new user: {}",user);

        return user;
    }

    @PutMapping("updateUsernameById")
    public User updateUsernameById(String username, int id) {
        User user = new User();
        user.setId(id);
        user.setUsername(username);
        return user;
    }

    @PostMapping("addUser")
    public User addUser(@RequestBody User user) {
        return user;
    }

    @DeleteMapping("deleteUserById/{id}")
    public void deleteUserById(@PathVariable Long id) {

    }

    @GetMapping("hello")
    public String hello(String name) {
        return "hello " + name + " !";
    }
}
